# -*- coding: utf-8 -*-

from flask import Flask, request, session, url_for, redirect, \
    g

from web.app.models import User

app = Flask(__name__)

PER_PAGE = 20
app.config.update(dict(
    DEBUG=True,
    SECRET_KEY='development key',
))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)


@app.before_request
def before_request():
    g.user = None
    if 'login_user' in session:
        g.user = User.query.filter(User.id == session['login_user']).first()
    elif request.path != '/login':
        app.logger.debug(request.path)
        return redirect(url_for('login'))





# @app.errorhandler(404)
# def not_found(error):
#     return render_template('error.html'), 404
